package com.bprogram.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.bprogram.controller.UserFeign;
import com.bprogram.pojo.User;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Autowired
  private UserFeign userFeign;
    //新增默认字段默认值
    @Override
    public void insertFill(MetaObject metaObject) {
        User user = userFeign.getLoginUser();
        this.setFieldValByName("createId", user.getUserId(), metaObject);
        this.setFieldValByName("createCode", user.getUserCode(), metaObject);
        this.setFieldValByName("createName", user.getUserName(), metaObject);
        this.setFieldValByName("createTime", null, metaObject);


    }
    //修改时默认值
    @Override
    public void updateFill(MetaObject metaObject) {
        User user = userFeign.getLoginUser();
        this.setFieldValByName("updateId", user.getUserId(), metaObject);
        this.setFieldValByName("updateCode", user.getUserCode(), metaObject);
        this.setFieldValByName("updateName", user.getUserName(), metaObject);

    }

}